<?php
//include("utils.php");

include("header.php");

include_once("UserIncludes/DbConfig.php");
include_once("UserIncludes/site_specific_function.php");
?>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<link rel="stylesheet" href="css/listing.css" type="text/css" />
<link rel="stylesheet" href="css/style.css" type="text/css" />
<link href="css/global.css" rel="stylesheet" type="text/css">
<?php
if($_POST['modereg']=="registration")
{

 	registration();
//echo "<script>alert('hi11')</script>";
}
else
{
//main_content("reg();");
main();
//echo "<script>alert('hi2')</script>";
}

function UserNameAvailavility($Username)
{
	$SELECTusername="SELECT `username` FROM siteusers WHERE `username`='".$Username."'";
	
	$EXECUTIONofSELECTusername=mysql_query($SELECTusername);
	if(mysql_num_rows($EXECUTIONofSELECTusername) > 0)
	{
		return 'Y';
	}
	else
	{
		return 'N';
	}
	
}

function UserEmailAvailavility($EMAil)
{

	$SELECTusername="SELECT `email` FROM siteusers WHERE `email`='".$EMAil."'";
	$EXECUTIONofSELECTusername=mysql_query($SELECTusername);
	if(mysql_num_rows($EXECUTIONofSELECTusername) > 0)
	{
	return 'Y';
	}
	else
	{
		return 'N';
	}
	
}
function check_input($value)
{
if( get_magic_quotes_gpc() )
{
$value = stripslashes( $value );
}
//check if this function exists
if( function_exists( "mysql_real_escape_string" ) )
{
$value = mysql_real_escape_string( $value );
}
//for PHP version < 4.3.0 use addslashes
else
{
$value = addslashes( $value );
}
return $value;
}

function Registration()
{

	if($_POST['modereg']=="registration")
	{
		$pass=$_POST['PassWord'];
		$fname=$_POST['FirstName'];
		$lname=$_POST['LastName'];
		$phno=$_POST['MOBIle'];
		$comp=$_POST['CompName'];
		$PASS=check_input($pass);
		$FIRSTNAME=check_input($fname);
		$LASTNAME=check_input($lname);
		$PHNO=check_input($phno);
		$COMP=check_input($comp);
		$passencoded=md5	($PASS);
		$DATEtoday = date('Y/m/d H:m:s');
		
		$Register=$_POST['SubmitForm'];
		if(isset($Register) && $Register == 'Register')
		{
			/***************************************** SET THE USER NAME START HERE *********************************************/
			$RESUltUSERnameVALidatioN=UserNameAvailavility($_POST['UserName']);
			if($RESUltUSERnameVALidatioN == 'N')
			{
				$uname=$_POST['UserName'];
				$USERNAME=check_input($uname);
				//echo '<script>alert("'.$USERNAME.'");</script>';	
				$DISPLAymessAGES="";
			}
			else
			{
				$GLOBALS['regmsg']="USer Name Is Alrady Exist.";
			}
			
			/***************************************** SET THE USER EMIL STARTS HERE *********************************************/
			$RESUltEMAilVALidatioN=UserEmailAvailavility($_POST['EmaiL']);
			if($RESUltEMAilVALidatioN == 'N')
			{
				$email=$_POST['EmaiL'];
				$EMAIL=check_input($email);
				//echo '<script>alert("'.$EMAIL.'");</script>';	
				$DISPLAymessAGES1="";
			}
			else
			{
				$GLOBALS['regmsg']="Email Is Alrady Exist.";
			}
			/***************************************** SET THE USER EMIL ENDS HERE *********************************************/
			$SELECT_sitedetails="select * from global_settings";
			$EXE_sitedetails=mysql_query($SELECT_sitedetails);
			$ROW_sitedetails=mysql_fetch_array($EXE_sitedetails);
			if($USERNAME!=''&& $EMAIL!='')
			{
				$selectlang="SELECT * FROM ".LANGUAGE;
				$QUERYLANG=mysql_query($selectlang);
				
				/*while($fetlang=mysql_fetch_array($QUERYLANG))
				{
					$insertSql="INSERT INTO ".SITEUSER." SET `username`='".$USERNAME."',`password`='".$passencoded."',`fName`='".$FIRSTNAME."',`lName`='".$LASTNAME."',`email`='".$EMAIL."',`phone`='".$PHNO."',`company`='".$COMP."',`registrationDate`='".$DATEtoday."',`userType`='G',`status`='P',`langId`='".$fetlang['langId']."'";
					//echo $insertSql;die;
					$RETURnMAsterQuery=mysql_query($insertSql);
				}*/
				//header("location:".$GLOBALS['site_url']);
				
				#################################### code on 08_07_09 starts here #################################
					
					$message="<table width='100%' border='1' cellspacing='0' cellpadding='0'>websiteName 
							
							<tr>
							<td>Hi ".$FIRSTNAME." ".$LASTNAME." -- Thanks for joining ".$ROW_sitedetails['websiteName']."!<br>Here's your account info for logging in:</td>
							</tr>
							
							<tr><td>&nbsp;</td></tr>
							
							<tr>
							<td>
							<table width='75%' align='center' cellpadding='2' cellspacing='2' style=' font-family:Arial, Helvetica, sans-serif; font-size:12px;background-color:#CCCCCC; border:1px solid #333333;'>
							<tr>
							<td align='left' width='30%'><strong>&nbsp;Email Id</strong></td>
							<td align='left' width='10%'><strong>:</strong></td>
							<td align='left' width='60%'>".$EMAIL."</td>
							</tr>
							
							<tr><td colspan='3'>&nbsp;</td></tr>
							
							<tr>
							<td align='left' width='30%'><strong>&nbsp;Password</strong></td>
							<td align='left' width='10%'><strong>:</strong></td>
							<td align='left' width='60%'>".$pass."</td>
							</tr>
							</table>
							</td>
							</tr>
							
							<tr><td>&nbsp;</td></tr> 
							
							<tr>
							<td>At ".$ROW_sitedetails['websiteName ']." we care about your privacy. This email is never sent unsolicited.<br>
							<br>If you think you've received this email in error or if you have any questions or concerns regarding your privacy, please contact us at:<br>
							<br><a href='mailto:".$ROW_sitedetails['adminEmail']."'>".$ROW_sitedetails['adminEmail']."</a><br>
							<br>Copyright (c) ".date('Y')." ".$ROW_sitedetails['websiteName'].". All Rights Reserved.</td>
							</tr>
							
							<tr><td>&nbsp;</td> </tr>
							
							</table>";
					$to=$EMAIL;
					$subject = "Thankyou for registering at ".$ROW_sitedetails['websiteName'];
					$headers = "MIME-Version: 1.0\r\n";
					$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
					$headers .= "From: ".$ROW_sitedetails['adminEmail'];
					//$headers .= "From: postmater@localhost.com";
					
					//echo $message;
					$send = mail($to, $subject, $message, $headers);
					if(!$send)
					{
						echo "Error: Can't send mail.";
					}
					else
					{
						//quy.nh update 29.12.2009
						$insertSql="INSERT INTO ".SITEUSER."(username,password,fName,lName,email,phone,company,registrationDate,userType,status,langId)
								VALUES('".$USERNAME."','".$passencoded."','".$FIRSTNAME."','".$LASTNAME."','".$EMAIL."','".$PHNO."','".$COMP."','".$DATEtoday."','G','P','1')";
						$RETURnMAsterQuery=mysql_query($insertSql);
						if(!$RETURnMAsterQuery){
							echo "Error: Can't insert database.";die;
						}else{
							echo '<script>window.location="start.php";</script>'; 
						}
					}
					
					//print('<script>window.location.href="viewprofile.php";</script>');
					
					#################################### code on 08_07_09 ends here ####################################
					
					
				
			}
			
		}
	}
//main_content("reg();");
main();

}
function main()
{
//echo "<script>alert('hi')</script>";		?> 
<script language="javascript" src="JavaScripts/registration.js"></script>
<!--<link rel="stylesheet" href="css/style.css" type="text/css" />-->
<form id="RegisTRationForm" name="RegisTRationForm" method="post" action="" onsubmit="return regformvalidation();">
<input type="hidden" name="modereg" value="registration" /><br />
<br />
<table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td valign="top" align="center"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
                  <tr>
                    <td width="20%" valign="top"><?php // include("left_pannel.php"); ?></td>
                    <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="11"><img src="images/PinkBorderTopLeft.jpg" alt="" width="11" height="11"></td>
                              <td class="PinkBoxTopBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
                              <td width="11"><img src="images/PinkBorderTopRight.jpg" alt="" width="11" height="11"></td>
                            </tr>
                        </table></td>
                      </tr>
                      <tr>
                        <td class="PinkTwosideBorder" valign="top">
	

				<table width="100%" border="0" cellspacing="0" cellpadding="0">
			
					<tr>
						<td><img src="images/spacer.gif" alt="" width="10" height="7"></td>
					</tr>
					<tr>
						<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
						<tr>
						<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td width="29"><img src="images/TitleArrowLeft.jpg" alt="" width="29" height="30"></td>
							<td class="MarketTitleBg"><?php echo TOBUYADS;?></td>
						</tr>
						</table></td>
						</tr>
						<tr>
						<td>&nbsp;</td>
						</tr>
						<tr>
						<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr><td colspan="2" style="color:#FF0000; font-weight:bold;font-size:12px" align="center"><?php if($GLOBALS['regmsg']!=''){ echo $GLOBALS['regmsg'];} ?></td></tr>
						<tr>
								<td width="154" valign="top">&nbsp;</td>
								<td valign="top">
								<table border="0" cellspacing="0" cellpadding="0" >
							<tr>
								<td width="110" height="30">
								
								<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td width="3"><img src="images/FormNameBoxLeft.jpg" alt="" width="3" height="18"></td>
								<td class="FormNameBoxBg"><?php echo USER_NAME?>:</td>
								<td width="13"><img src="images/FormNameBoxRight.jpg" alt="" width="13" height="18"></td>
							</tr>
							</table></td>
								<td width="14">&nbsp;</td>
								<td ><input name="UserName" type="text" class="InputBox" id="UserName" value="<?php echo $_POST['UserName'];?>"><span id="UserNameError" style="display:block; color:#FF0000; font-weight:bold; font-size:11px;"></span></td>
								<td width="11">&nbsp;</td>
								<td>&nbsp;</td>
							</tr>
							<tr>
							<td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td width="3"><img src="images/FormNameBoxLeft.jpg" alt="" width="3" height="18"></td>
								<td class="FormNameBoxBg"><?php echo PASS_WORD?>:</td>
								<td width="13"><img src="images/FormNameBoxRight.jpg" alt="" width="13" height="18"></td>
							</tr>
							</table></td>
								<td>&nbsp;</td>
								<td><input name="PassWord" type="password" class="InputBox" id="PassWord" value="<?php echo $_POST['PassWord'];?>"><span id="PassWordError" style="display:none; color:#FF0000; font-weight:bold; font-size:11px;"></span></td>
								<td>&nbsp;</td>
								<td>&nbsp;</td>
							</tr>
							<tr>
							<td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td width="3"><img src="images/FormNameBoxLeft.jpg" alt="" width="3" height="18"></td>
								<td class="FormNameBoxBg"><?php echo RETYPEPASSWORD ?>:</td>
								<td width="13"><img src="images/FormNameBoxRight.jpg" alt="" width="13" height="18"></td>
							</tr>
							</table></td>
								<td>&nbsp;</td>
								<td><input name="RPassWord" type="password" class="InputBox" id="RPassWord" value="<?php echo $_POST['RPassWord'];?>"><span id="RPassWordError" style="display:none; color:#FF0000; font-weight:bold; font-size:11px;"></span></td>
								<td>&nbsp;</td>
								<td>&nbsp;</td>
							</tr>
							<tr>
							<td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td width="3"><img src="images/FormNameBoxLeft.jpg" alt="" width="3" height="18"></td>
								<td class="FormNameBoxBg"><?php echo FIRSTNAME?>:</td>
								<td width="13"><img src="images/FormNameBoxRight.jpg" alt="" width="13" height="18"></td>
							</tr>
							</table></td>
								<td>&nbsp;</td>
								<td><input name="FirstName" type="text" class="InputBox" id="FirstName" value="<?php echo $_POST['FirstName'];?>"><span id="FirstNameError" style="display:none; color:#FF0000; font-weight:bold; font-size:11px;"></span></td>
								<td>&nbsp;</td>
								<td>&nbsp;</td>
							</tr>
							<tr>
							<td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td width="3"><img src="images/FormNameBoxLeft.jpg" alt="" width="3" height="18"></td>
								<td class="FormNameBoxBg"><?php echo LASTNAME?>:</td>
								<td width="13"><img src="images/FormNameBoxRight.jpg" alt="" width="13" height="18"></td>
							</tr>
							</table></td>
								<td>&nbsp;</td>
								<td><input name="LastName" type="text" class="InputBox" id="LastName" value="<?php echo $_POST['LastName'];?>"><span id="LastNameError" style="display:none; color:#FF0000; font-weight:bold; font-size:11px;"></span></td>
								<td>&nbsp;</td>
								<td>&nbsp;</td>
							</tr>
			
							<tr>
							<td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td width="3"><img src="images/FormNameBoxLeft.jpg" alt="" width="3" height="18"></td>
								<td class="FormNameBoxBg"><?php echo EMAIL?>:</td>
								<td width="13"><img src="images/FormNameBoxRight.jpg" alt="" width="13" height="18"></td>
							</tr>
							</table></td>
								<td>&nbsp;</td>
								<td><input name="EmaiL" type="text" class="InputBox" id="EmaiL" value="<?php echo $_POST['EmaiL'];?>"><span id="EmaiLError" style="display:none; color:#FF0000; font-weight:bold; font-size:11px;"></span></td>
								<td>&nbsp;</td>
								<td>&nbsp;</td>
								</tr>
			
							<tr>
								<td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td width="3"><img src="images/FormNameBoxLeft.jpg" alt="" width="3" height="18"></td>
								<td class="FormNameBoxBg"><?php echo PHNO?>:</td>
								<td width="13"><img src="images/FormNameBoxRight.jpg" alt="" width="13" height="18"></td>
							</tr>
							</table></td>
								<td>&nbsp;</td>
								<td><input name="MOBIle" type="text" class="InputBox" id="MOBIle" value="<?php echo $_POST['MOBIle'];?>"><span id="MOBIleError" style="display:none; color:#FF0000; font-weight:bold; font-size:11px;"></span></td>
								<td>&nbsp;</td>
								<td>&nbsp;</td>
							</tr>
							<tr>
							<td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td width="3"><img src="images/FormNameBoxLeft.jpg" alt="" width="3" height="18"></td>
								<td class="FormNameBoxBg"><?php echo COMPANYNAME?>:</td>
								<td width="13"><img src="images/FormNameBoxRight.jpg" alt="" width="13" height="18"></td>
							</tr>
							</table></td>
								<td>&nbsp;</td>
								<td><input name="CompName" type="text" class="InputBox" id="CompName" value="<?php echo $_POST['CompName'];?>"><span id="CompNameError" style="display:none; color:#FF0000; font-weight:bold; font-size:11px;"></span></td>
								<td>&nbsp;</td>
								<td>&nbsp;</td>
							</tr>
<!-- ======================================================================================================================================== -->
							<tr><td colspan="5">&nbsp;</td></tr>
							<tr>
								<td height="30" colspan="5">
									<table width="100%" border="0" cellspacing="0" cellpadding="0">
									<tr>
										
										<td style="font-family: Arial;font-size: 12px;color:#000000; border=none;"><input type="checkbox" name="terms" id="terms" >&nbsp;<?php echo AGREE?> <a href="terms.php" class="register_link"><?php echo TERMS?></a><span id="termsError" style="display:none; color:#FF0000; font-weight:bold; font-size:11px;"></span></td>
										
									</tr>
									</table>
								</td>
								
							</tr>
<!--================================================================================================ =====================================	 -->
							<tr>
								<td height="30">&nbsp;</td>
								<td>&nbsp;</td>
								<td align="right" valign="bottom"><input name="Submit" type="submit" class="SubmitInputButton" id="submit" value="<?php echo REGISTER?>"><input type="hidden" name="SubmitForm" id="SubmitForm" value="<?php echo REGISTER?>" /></td>
								<td>&nbsp;</td>
								<td>&nbsp;</td>
							</tr>
			
							</table></td>
						</tr>
						</table></td>
						</tr>
						</table></td>
					</tr>
					<tr>
						<td><img src="images/spacer.gif" alt="" width="10" height="7"></td>
					</tr>
					</table>
			
		</td>
                      </tr>
                      <tr>
                        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="11"><img src="images/PinkBorderBottomLeft.jpg" alt="" width="11" height="11"></td>
                              <td class="PinkBoxBottomBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
                              <td width="11"><img src="images/PinkBorderBottomRight.jpg" alt="" width="11" height="11"></td>
                            </tr>
                        </table></td>
                      </tr>
                    </table></td>
                    <td width="20%">&nbsp;</td>
                    </tr>
                </table></td>
              </tr>
            </table>
</form>
            
<?php
        include("footer.php");
}
		?> 